//
// Created by liu on 2020/10/28.
//
#pragma once
#ifndef IRAY_PROJECT1_CONFIG_H
#define IRAY_PROJECT1_CONFIG_H

#include <iostream>
#include <unordered_map>
#include <fstream>
#include "json.h"
#include "opencv2/opencv.hpp"
using namespace std;

namespace alg{

    struct DetObjectStr
    {
        cv::Rect_<float> rect;
        int label;
        float score;
    };


    class Config{
    public:
        static Config& instance(){
            static Config s_instance;
            return s_instance;
        }
        int parse_config(std::string const& conf_path);

        int int_conf(std::string const&key,int defautlt_value){
            auto iter = int_conf_.find(key);
            if(iter!=int_conf_.end()){
                return iter->second;
            }
            return defautlt_value;
        }

        float float_conf(std::string const&key,float default_value){
            auto iter =float_conf_.find(key);
            if(iter!= float_conf_.end()){
                return  iter->second;
            }
            return default_value;
        }

        std::vector<int> str_conf(std::string const&key,vector<int> default_value){
            auto iter = str_conf_.find(key);
            if(iter!= str_conf_.end()){
                return  Split(iter->second,",");
            }
            return default_value;
        }
        std::string str_conf(std::string const&key){
            auto iter = str_conf_.find(key);
            if(iter!= str_conf_.end()){
                return iter->second;
            }
        }
        const char* char_conf(std::string const&key ){
            auto iter = str_conf_.find(key);
            if(iter!= str_conf_.end()){
                return iter->second.data();
            }
        }
        std::vector<int> Split(const std::string& src, const std::string& separator);
    private:
        Config(){}
        std::unordered_map<std::string,int>     int_conf_;
        std::unordered_map<std::string,float>   float_conf_;
        std::unordered_map<std::string,std::string>  str_conf_;
    };

}

#endif //IRAY_PROJECT1_CONFIG_H
